package day21.fefei;

import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.Arrays;

public class InetAddress_Demo {
    public static void main(String[] args) throws UnknownHostException {
        InetAddress localhost=InetAddress.getLocalHost();
        System.out.println(localhost);//LAPTOP-K8KFJQ4E/192.168.217.11  本机主机名称、本机IP地址
        InetAddress baiduhost = InetAddress.getByName("www.baidu.com");
        System.out.println(baiduhost);
        InetAddress[] allbaiduhost = InetAddress.getAllByName("www.baidu.com");
        System.out.println(Arrays.toString(allbaiduhost));

//获取百度主机的主机名
        String hostName=baiduhost.getHostName();
        System.out.println(hostName);
      //  获取主机的IP地址
        String hostAddress = baiduhost.getHostAddress();
        System.out.println(hostAddress);
    }
}
